package timepicker.com.timepickerdemo;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity {


    boolean iscomplete;
    String str_star;
    String str_end;
    TimePickerView pvTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    public  void test(View view)
    {
//时间选择器
        if (pvTime==null)
        {
            pvTime = new TimePickerBuilder(MainActivity.this, new OnTimeSelectListener() {
                @Override
                public void onTimeSelect(Date date, View v) {
                    if (iscomplete) {
                        str_end=getTime(date);
                        Toast.makeText(MainActivity.this, "结束"+getTime(date), Toast.LENGTH_SHORT).show();
                        iscomplete=false;


                    }else {
                        iscomplete=true;
                        str_star=getTime(date);
                        Toast.makeText(MainActivity.this, "开始"+getTime(date), Toast.LENGTH_SHORT).show();
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                pvTime.show();

                            }
                        },1000);



                    }
                }
            }).build();

        }


        pvTime.show();




    }
    private String getTime(Date date) {//可根据需要自行截取数据显示
        Log.d("getTime()", "choice date millis: " + date.getTime());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        return format.format(date);
    }

}
